﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using CH.Easy.DbProvider.Common;
using CH.Easy.DbProvider.Mapping;
namespace CH.Easy.DbProvider.ExpressionExtend
{
    public class RemoveExpression : Expression
    {
    
        public Expression Expression { get; set; }
        public string Alias { get; set; }
        public string Name { get; set; }
        public string PrimaryKey { get; set; }
        public RemoveExpression(Type t, Expression expression)
        {
         
            this.Expression = expression;
      
            
          
            this.Alias = "T" + t.GetHashCode();
            this.Name = t.Name;
            this.PrimaryKey = "ID";
            var attributes = t.GetCustomAttributes(typeof(TableMappingAttribute), true);
            if (attributes != null && attributes.Count() > 0)
            {
                foreach (var attribute in attributes)
                {
                    TableMappingAttribute a = attribute as TableMappingAttribute;
                    if (a != null)
                    {

                        this.Name = a.Name;
                        this.PrimaryKey = a.PrimaryKey;
                    }
                }
            }
        }
        public override ExpressionType NodeType
        {
            get
            {
                return (ExpressionType)ExpressionTypeExend.Delete;
            }
        }

        public override Type Type
        {
            get
            {

                return typeof(int);
            }
        }
    }
}
